package com.wei.spring.web.user.util;

import com.wei.spring.web.user.exception.BusinessException;
import com.wei.spring.web.user.model.dto.ResponseCodeEnum;
import com.wei.spring.web.user.model.vo.ResultData;

/**
 * 类的详细说明
 *
 * @author buhuan.wang
 * @since 2020/12/21
 */
public class ResultUtil {
    public static ResultData getSuccess(Object result) {
        ResultData resultData = new ResultData();
        resultData.setSuccess(true);
        resultData.setErrorCode(ResponseCodeEnum.SUCCESS.getCode());
        resultData.setErrorMsg(ResponseCodeEnum.SUCCESS.getMessage());
        resultData.setResult(result);
        return resultData;
    }

    public static ResultData getError(BusinessException e) {
        ResultData resultData = new ResultData();
        resultData.setSuccess(false);
        resultData.setErrorCode(e.getCode());
        resultData.setErrorMsg(e.getMessage());
        return resultData;
    }

    public static ResultData getError(ResponseCodeEnum responseCodeEnum) {
        ResultData resultData = new ResultData();
        resultData.setSuccess(false);
        resultData.setErrorCode(responseCodeEnum.getCode());
        resultData.setErrorMsg(responseCodeEnum.getMessage());
        return resultData;
    }

    public static ResultData getError() {
        return getError(ResponseCodeEnum.SYSTEM_ERROR);
    }
}
